// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import API from '@admin/views/System/User/UserRegion/store/API'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async remoteList({ state: { info: { id, areaId } } }) {
    if (!id) return [0, []]

    const list = (CORE.REGION.MAP[areaId] || []).children
    return [list.length, transList(list)]
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async remoteEdit({ state: { one } }) {
    const pre = one.location === 'none' ? '清除' : '标记'

    const msg = await API.edit(one, `${pre}${CORE.MAP.REGION}`)

    delete sessionStorage.REGION
    await CORE.initCORE() // 更新内核区域

    return msg
  },
}

// ============================== 转换方法 ============================== //

const transList = (arr) => {
  return arr
}
